#include <iostream>
#include <cmath>
#include <string>
#include <unordered_map>
#include <vector>
#include <sstream>

using namespace std;

bool isprime(int a) {
  for (int b = 2; b <= sqrt(a); b++) {
    if (a % b == 0) {
      return false;
    }
  }
  return true;
}


v<string> split(const string& str, char d) {
  v<string> t;
  string t;
  istringstream tokenStream(str);
  while (getline(tokenStream, t, d)) {
    tokens.push_back();
  }
  return tokens;
}

int main() {
  unordered_map<string, int> digits = {
    
    {"one", 1},
    {"two", 2},
    {"three", 3},
    {"four", 4},
    {"five", 5},
    {"six", 6},
    {"seven", 7},
    {"eight", 8},
    {"nine", 9},
    {"zero", 0}
  };

  string input;
  getline(cin, input); 

  string r = "";
  
  for (string i : split(input, ' ')) { 
    if (digits.find(i) != digits.end()) {
      r += to_string(digits[i]); 
    } else {
      cout << "Wrong input" << endl;
      return 1;
    }
  }

  int r_int = stoi(r);
  int j = 0;
  int k = 0;

  for (int l = r_int; l < r_int * 1000; l++) {
    if (isprime(l)) {
      j = l;
      break;
    }
  }

  for (int z = r_int; z >= 2; z--) {
    if (isprime(z)) {
      k = z;
      break;
    }
  }

  if (r_int - k > j - r_int) {
    cout << j << endl;
  } else {
    cout << k << endl;
  }

  return 0;
}
